﻿using System.Reflection;

namespace ConsoleApp13
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            //CancellationTokenSource cts = new CancellationTokenSource();
            //_ = Task.Run(async () =>
            // {
            //     await Test2(cts);
            // }, cts.Token);


            ////await Task.Delay(2500);
            ////_ = Task.Run(async () =>
            ////{
            ////    cts.Cancel();
            ////    cts = new CancellationTokenSource();
            ////    await Test2(cts);
            ////}, cts.Token);



            ////await Task.Delay(5000);
            ////cts.Cancel();

            //Console.ReadLine();


        }



        public static void Test(Delegate @delegate)
        {

            MethodInfo methodInfo = @delegate.GetMethodInfo();
        }
        private static bool m_isExit = false;


        private async static Task Test2(CancellationTokenSource cancellationTokenSource)
        {
            try
            {
                while (!m_isExit && !cancellationTokenSource.Token.IsCancellationRequested)
                {
                    await Task.Delay(1000);
                    Console.WriteLine("正在运行");
                }
                Console.WriteLine("线程被取消了");
            }
            catch (OperationCanceledException ex)
            {

                throw;
            }


        }

    }
}
